package algorithm.action;

import datastructure.TreeNode;

public class TreeDepth {

	public static void main(String[] args) {
		int[] preOrder = {1,2,4,7,3,5,6,8};
		int[] inOrder = {4,7,2,1,5,3,8,6};
		TreeNode tree = ReconstructBinaryTree.reconstructBinaryTree(preOrder, inOrder);
		System.out.println(treeDepth(tree));
	}
	
	static int depth = 0;

	static public int treeDepth(TreeNode root) {
        if(root == null) return 0;
        treeDepth(root, 0);
        return depth;
    }
	
	static void treeDepth(TreeNode root, int n) {
		if(root != null) {
			treeDepth(root.left, n+1);
			treeDepth(root.right, n+1);
		} else {
			if(depth < n) depth = n;
		}
		
	}
}
